package com.wjjun.library.widget.dropdown;

import android.annotation.SuppressLint;
import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.wjjun.library.R;


/**
 * 基础的下拉弹窗tab控件
 * author : wangjunjun
 * date   : 2021/10/21
 * desc   :
 */
public abstract class BaseMenuTabView extends androidx.appcompat.widget.AppCompatTextView {

    protected DropDownView dropDownView;

    protected View contentView;

    protected OnDropDownListener onDropDownListener;

    public BaseMenuTabView(@NonNull Context context) {
        this(context, null);
    }

    public BaseMenuTabView(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public BaseMenuTabView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    protected void init() {
        setSingleLine(true);
        setEllipsize(TextUtils.TruncateAt.END);
    }

    protected abstract View initContentView();

    public void bindDropDownView(DropDownView dropDownView) {
        this.dropDownView = dropDownView;
    }

    public void onChange(boolean isShow) {
        setSelected(isShow);
    }

    public View getContentView() {
        if (contentView == null) {
            contentView = initContentView();
        }
        return contentView;
    }

    protected void onConfirm() {
        dropDownView.closeMenu();
        if (onDropDownListener != null) {
            onDropDownListener.onConfirm(this);
        }
    }

    public boolean isShow() {
        return dropDownView.isShowing();
    }

    public OnDropDownListener getOnDropDownListener() {
        return onDropDownListener;
    }

    public void setOnDropDownListener(OnDropDownListener onDropDownListener) {
        this.onDropDownListener = onDropDownListener;
    }
}
